Skip to content

feat: add /api/recommend schema validation and structured error responses#1256

Open
divyanshim27 wants to merge 8 commits into
komalharshita:mainfrom
divyanshim27:feat/api-schema-validation
Open

feat: add /api/recommend schema validation and structured error responses#1256
divyanshim27 wants to merge 8 commits into
komalharshita:mainfrom
divyanshim27:feat/api-schema-validation

Conversation

@divyanshim27

@divyanshim27 divyanshim27 commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Implements all acceptance criteria from issue #1231.

Changes Made

utils/schemas.py (new file)

  • RecommendRequest dataclass with validate() method
  • Validates: skills (non-empty list), level (Beginner/Intermediate/Advanced), interest (non-empty string), time (Low/Medium/High)
  • Returns a list of human-readable error strings

routes/main_routes.py (modified)

  • /api/recommend now returns HTTP 400 for non-JSON body (INVALID_CONTENT_TYPE)
  • /api/recommend now returns HTTP 422 for validation errors (VALIDATION_ERROR)
  • All success responses follow {"success": true, "count": N, "results": [...]}

scripts/validate_projects.py (new file)

  • Validates every entry in data/projects.json for required fields
  • Checks field types and valid values for level and time
  • Exits with code 1 on failure (CI-safe)

.github/workflows/validate_projects.yml (new file)

  • Runs validate_projects.py on every PR that touches data/projects.json

tests/test_basic.py (modified — 5 new tests added)

  • test_empty_skills_returns_422
  • test_invalid_level_returns_422
  • test_valid_request_returns_200_with_structured_response
  • test_non_json_body_returns_400
  • test_validate_projects_script_catches_missing_field

Test Results

32 passed, 0 failed (27 original + 5 new)

Checklist

Closes #1231

- Add BookmarkManager (localStorage) with 10-item cap and duplicate prevention
- Add bookmark toggle button on project detail page
- Add /bookmarks route and template
- Track last 5 recently viewed projects via Flask session
- Add /api/recently-viewed endpoint
- Add homepage recently-viewed section
- Add 4 backend tests; bookmark JS logic covered by manual QA (no JS test runner in repo)

Closes komalharshita#1230
…nses

- Add utils/schemas.py: RecommendRequest dataclass with validate() method
  - Validates skills (non-empty list), level (Beginner/Intermediate/Advanced),
    interest (non-empty), time (Low/Medium/High)
- Update routes/main_routes.py: /api/recommend now returns:
  - HTTP 400 for non-JSON body (code: INVALID_CONTENT_TYPE)
  - HTTP 422 for validation errors (code: VALIDATION_ERROR, errors: [...])
  - HTTP 200 success: {success: true, count: N, results: [...]}
- Add scripts/validate_projects.py: validates all entries in data/projects.json
  for required fields and valid field values; exits 1 on failure for CI
- Add .github/workflows/validate_projects.yml: CI step runs validator on PRs
- Add 5 new tests in tests/test_basic.py (32 total, 0 failures):
  - empty skills → 422
  - invalid level → 422
  - valid input → 200 with structured response
  - non-JSON body → 400
  - validator catches missing project fields

Closes komalharshita#1231
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

@divyanshim27 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

@komalharshita

Copy link
Copy Markdown
Owner

@divyanshim27 kindly resolve the merge conflicts

@komalharshita komalharshita added the need review Further information is requested label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants